/**
 * 这是一个electron主进程与渲染进程的桥接文件
 * 暴露API供两者进行通讯
 */

const { contextBridge, ipcRenderer } = require('electron')

// 主进程、渲染进程通讯方法
contextBridge.exposeInMainWorld('electronAPI', {
    // 主进程监听
    serviceStart: (data) => ipcRenderer.invoke('serviceStart', data),
    serviceClose: (data) => ipcRenderer.invoke('serviceClose', data),
    serviceDel: (data) => ipcRenderer.invoke('serviceDel', data),
    serviceDelAll: () => ipcRenderer.invoke('serviceDelAll'),

    routeAdd: (data) => ipcRenderer.invoke('routeAdd', data),
    routeDel: (data) => ipcRenderer.invoke('routeDel', data),
    routeInit: (data) => ipcRenderer.invoke('routeInit', data),

    // 渲染进程监听
    serviceStartSuccess: (data) => ipcRenderer.on('serviceStartSuccess', data),
    serviceCloseSuccess: (data) => ipcRenderer.on('serviceCloseSuccess', data),
    serviceDelSuccess: (data) => ipcRenderer.on('serviceDelSuccess', data),
    serviceDelAllSuccess: (data) => ipcRenderer.on('serviceDelAllSuccess', data),

    routeAddSuccess: (data) => ipcRenderer.on('routeAddSuccess', data),
    routeDelSuccess: (data) => ipcRenderer.on('routeDelSuccess', data),
    routeInitSuccess: (data) => ipcRenderer.on('routeInitSuccess', data)
})
